﻿using M_Quality.API.Application.Command.QualitygroupCommand;
using M_Quality.Repository.Interface;
using MediatR;

namespace M_Quality.API.Application.CommandHandler.QualitygroupHandler
{
    public class QualitygroupDeleteCommandHandler : IRequestHandler<QualitygroupDeleteCommand, int>
    {
        protected readonly IQualitygroupRepository qualitygroupRepository;

        public QualitygroupDeleteCommandHandler(IQualitygroupRepository qualitygroupRepository)
        {
            this.qualitygroupRepository = qualitygroupRepository;
        }

        public async Task<int> Handle(QualitygroupDeleteCommand request, CancellationToken cancellationToken)
        {
            var id = request.QualitygroupId;
           foreach (var item in id)
            {
                var res = await qualitygroupRepository.GetModelAsync(item);
                res.IsDeleted = true;
      
                await qualitygroupRepository.UpdateAsync(res);
            }
            return 1;
        }
    }
}
